﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerDistance : MonoBehaviour
{
    public Transform PlayerPos;
    private float dis;
    public float AttackDis;
    public Animation AttackAnim;
    public float attackFrequence;//攻击频率
    private float lastTime;//记录上次攻击的时间
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        dis = (transform.position - PlayerPos.position).sqrMagnitude;
        if (dis < AttackDis&&Time.time>lastTime+attackFrequence)
        {

            lastTime = Time.time;
            AttackAnim.Play();
        }
    }
}
